package 多线程.可重入锁;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * todo ReentrantLock 是怎么实现可重入的或者Sync里面是怎么实现的
 */
public class ReentrantLockDemo {
    public static void main(String[] args) {
        Lock lock = new ReentrantLock();
        try {
            lock.lock();
            System.out.println("外层加锁");
            try {
                lock.lock();
                System.out.println("内层加锁");
            } finally {
                lock.unlock();
                System.out.println("内层解锁");
            }
        } finally {
            lock.unlock();
            System.out.println("外层解锁");
        }
    }
}
